﻿/*************************************************************************************
     * CLR 版本：       4.0.30319.42000
     * 类 名 称：       CsGetFileDlg
     * 机器名称：       KAIKO
     * 命名空间：       PunchCard.Service
     * 文 件 名：       CsGetFileDlg
     * 创建时间：       2020/12/15 14:29:39
     * 作    者：       WongJunLiang
     * 说    明：
     * 修改时间：
     * 修 改 人：
*************************************************************************************/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PunchCard.Service
{
    class CsGetFileDlg
    {
        public static bool Win32_GetFilePath(ref string strPath)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Multiselect = false;//该值确定是否可以选择多个文件
            dlg.Title = "请选择文件";
            dlg.Filter = "All File|*.*" +
                        "|" +
                        "Excel_2|*.xls" +
                        "|" +
                        "Excel_1|*.xlsx";
            var result = dlg.ShowDialog();
            if (result == true)
                strPath = dlg.FileName;
            return (bool)result;
        }

        public static bool Win32_WriteNewFilePath(ref string strPath)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.Filter = "Excel|*.xls";
            bool? result = dlg.ShowDialog();
            if (result == true)
                strPath = dlg.FileName;
            return (bool)result;
        }

        public static bool Forms_GetFileName(ref string strPath)
        {
            System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
            dlg.Multiselect = false;//该值确定是否可以选择多个文件
            dlg.Title = "请选择文件夹";
            dlg.Filter = "Excel_1|*.xlsx" +
                          "|" +
                          "Excel_2|*.xls" +
                          "|" +
                          "All File|*.*";
            var result = dlg.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
                strPath = dlg.FileName;
            return result == System.Windows.Forms.DialogResult.OK ? true : false;
            //strGetFilePath = System.IO.Path.GetDirectoryName(dlg.FileName);
        }

        public static bool Forms_GetFileFolder(ref string strPath)
        {
            System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog();
            dlg.Description = "请选择加载文件的路径";
            var result = dlg.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
                strPath = dlg.SelectedPath;
            return result == System.Windows.Forms.DialogResult.OK ? true : false;
        }

    }
}
